//package cc.tuhaolicai.mt.user.mobile.business.repay;
//
//import cc.tuhaolicai.mt.model.DO.pays.payPlatform.result.TransferReturn;
//import cc.tuhaolicai.mt.model.JsonResult;
//import cc.tuhaolicai.mt.predefined.constant.SysConfigConstant;
//import cc.tuhaolicai.mt.predefined.tool.ToolLock;
//import cc.tuhaolicai.mt.service.common.TypeConst;
//import cc.tuhaolicai.mt.service.exception.service.PayerErrorException;
//import cc.tuhaolicai.mt.user.mobile.business.handler.BusinessHandler;
//import cc.tuhaolicai.mt.user.mobile.service.RepayServiceImpl;
//import com.google.common.collect.Maps;
//import org.asyou.redis.lock.ILock;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import java.util.Map;
//
///**
// * 第三方还款时返回业务失败时本地处理业务
// *
// * @author chenli
// * @create 2017-10-11
// */
//public class PayerReturnErrorHandler extends BusinessHandler {
//
//    private static final Logger log = LoggerFactory.getLogger(PayerReturnErrorHandler.class);
//
//    @Override
//    public void coreExecute() {
//        if (myFlag) {
//            //参数中获取第三方参数
//            TransferReturn transferReturn = (TransferReturn)params.get("transferReturn");
//            RepayServiceImpl repayService = (RepayServiceImpl)params.get("repayService");
//            Long loanId = Long.parseLong(transferReturn.getRemark2());
//            if (!"88".equals(transferReturn.getResultCode()) && !"87".equals(transferReturn.getResultCode())) {//第三方处理失败
//                Map<String, Object> params = Maps.newHashMap();
//                params.put("loanId", loanId);
//                ILock lock = ToolLock.Loan.loanIdLock(loanId);
//                if (lock != null) {
//                    try {
//                        JsonResult<Boolean> jsonResult = repayService.send("execRequestRepayError", params, TypeConst.JR.BooleanType);
//                        if (jsonResult.getHaveError() || !jsonResult.getData()) {
//                            log.info(SysConfigConstant.MY_LOG_NID + "还款操作异步回调service:还款失败,还原数据失败");
//                            throw new PayerErrorException("还款失败,还原数据失败");
//                        } else {
////                            return true;
//                        }
//                    } catch (Exception e) {
//                        throw new PayerErrorException(e.getMessage());
//                    } finally {
//                        lock.unlock();
//                    }
//                } else {
//                    log.info(SysConfigConstant.MY_LOG_NID + "还款操作异步回调service:当前标的正在占用，第三方会自动重试");
//                    throw new PayerErrorException("当前标的正在占用，第三方会自动重试");
//                }
//            }
//        }
//
//        if(nextFlag){
//            Map<String,Object> nextParams = Maps.newHashMap();
//            nextHandler.addParams(nextParams);
//            nextHandler.execute();
//        }
//    }
//}